package com.leapp.sk.ui.adapter

import android.content.Context
import android.content.Intent
import android.view.View
import com.example.mvp.adapter.BaseLibMultipleViewAdapter
import com.example.mvp.binder.BaseDataBinder
import com.example.mvp.delegate.BaseAdapterDelegate
import com.example.util.ISTECHER
import com.leapp.sk.R
import com.leapp.sk.bean.NotifyObjEntity
import com.leapp.sk.binder.BaseBinder
import com.leapp.sk.ui.activity.leave.LevelActivity
import com.leapp.sk.ui.activity.leave.TeacherLeaveActivity
import com.leapp.sk.ui.activity.notify.ClassNotifyActivity
import com.leapp.sk.ui.activity.notify.ExamineNotifyActivit
import com.leapp.sk.ui.activity.notify.SystemNotifyActivity
import com.leapp.sk.ui.activity.task.ParentingTaskActivity
import com.leapp.sk.ui.activity.task.TeacherParentTaskActivity
import com.example.util.finallist.SkKey
import com.leapp.sk.viewdelegate.adapter.notify.NotifyAdapterDelegate
import com.leapp.sk.viewdelegate.adapter.notify.SystemNotifyAdapterDelegate

/**
 * 通知适配器
 * @author  chaohaipeng  on 2018/7/26.
 */
class NotifyAdapter(context: Context, mlist: List<NotifyObjEntity>,isSystems:Boolean) : BaseLibMultipleViewAdapter<NotifyObjEntity>(context, mlist){

    /**
     * 数据
     */
    val mList = mlist
    /**
     * 上下文
     */
    val mContext = context
    /**
     * 是系统通知
     */
    val isSystem=isSystems

    override fun bindEvenListener(viewDelegate: BaseAdapterDelegate?, position: Int) {
        if (viewDelegate is NotifyAdapterDelegate ){
            viewDelegate.setOnClickListener(View.OnClickListener {
                val get = mList.get(position)
                setIntent(mContext,get.type )
            },R.id.rl_an_notify)


        }

    }

    override fun notifyView(viewDelegate: BaseAdapterDelegate?, position: Int) {
        if (viewDelegate is NotifyAdapterDelegate ){
            viewDelegate.setData(mContext,mList.get(position))
        }else if (viewDelegate is SystemNotifyAdapterDelegate){
            viewDelegate.setData(mContext,mList.get(position))
        }

    }

    override fun getDelegate(position: Int): BaseAdapterDelegate {
        if (isSystem){
            return SystemNotifyAdapterDelegate::class.java?.newInstance()
        }else{
            return NotifyAdapterDelegate::class.java?.newInstance()
        }
    }

    override fun getDataBinder(position: Int): BaseDataBinder<*, *> {
        return BaseBinder()
    }

    override fun getItemData(position: Int): Any {
        return mList.get(position)
    }


    /**
     * 设置左边图片
     */
    private fun setIntent(context: Context, type: Int) {
        when(type){
            SkKey.BTKEY_INT_0->{
                val intent=Intent(context,ClassNotifyActivity::class.java)
                context.startActivity(intent)
            }
            SkKey.BTKEY_INT_1->{
                if (ISTECHER){
                    val intent=Intent(context, TeacherParentTaskActivity::class.java)
                    context.startActivity(intent)
                }else{
                    val intent=Intent(context, ParentingTaskActivity::class.java)
                    context.startActivity(intent)
                }
            }
            SkKey.BTKEY_INT_2->{
                if (ISTECHER){
                    val intent=Intent(context, TeacherLeaveActivity::class.java)
                    context.startActivity(intent)
                }else{
                    val intent=Intent(context, LevelActivity::class.java)
                    context.startActivity(intent)
                }
            }
            SkKey.BTKEY_INT_3->{
                val intent=Intent(context, ExamineNotifyActivit::class.java)
                context.startActivity(intent)
            }
            SkKey.BTKEY_INT_4->{
                val intent=Intent(context, SystemNotifyActivity::class.java)
                context.startActivity(intent)
            }
        }

    }
}